package com.bhs.sansong.ui.dialog;

import android.content.Context;
import android.graphics.Color;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bhs.sansong.R;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lxj.xpopup.core.BubbleAttachPopupView;
import com.lxj.xpopup.util.XPopupUtils;

import java.util.List;

public class AttachMoreDialog2 extends BubbleAttachPopupView {


    private BaseQuickAdapter<String, BaseViewHolder> mAdapter;

    private List<String> mList;
    private RecyclerView mRvList;

    public AttachMoreDialog2(@NonNull Context context, List<String> mList) {
        super(context);
        this.mList = mList;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_attach_more2;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        setBubbleBgColor(Color.WHITE);
        setBubbleShadowSize(XPopupUtils.dp2px(getContext(), 6));
        setBubbleShadowColor(Color.parseColor("#C5C5C5"));
        setArrowWidth(XPopupUtils.dp2px(getContext(), 8));
        setArrowHeight(XPopupUtils.dp2px(getContext(), 9));
//                                .setBubbleRadius(100)
        setArrowRadius(XPopupUtils.dp2px(getContext(), 2));
        initView();
    }

    private MyClickListener2 listener;

    public void setMyClickListener(@Nullable MyClickListener2 l) {
        this.listener = l;
    }


    private void initView() {
        mRvList = findViewById(R.id.rv_list);
        mAdapter = new BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_attach, mList) {
            @Override
            protected void convert(@NonNull BaseViewHolder helper, String item) {
                helper.setText(R.id.tv_label, item);
            }
        };
        mRvList.setAdapter(mAdapter);
        mRvList.setLayoutManager(new LinearLayoutManager(getContext()));
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                listener.onClick(mList.get(position),null);
            }
        });

    }


}
